<?
	$gid = fgsBase::getParam(0);
	if (empty($gid))
		fgsBase::redirect('games');
		
	$game = fgsGames::get($gid);
	if ($game === false)
		fgsBase::redirect('games');

	// get logo if ask
	$cmd = fgsBase::getParam(1);
	$size = fgsBase::getParam(2);
	if ($cmd == 'logo' && !empty($game['logo_data'])) {
		switch ($size) {

			// TODO: make cache for this
			case 'icon16':
				$data = base64_decode($game['logo_data']);
				$im = imagecreatefromstring($data);
				$tim = imagecreatetruecolor(16, 16);
				if ($im && $tim) {
					imagealphablending($tim, false);
					imagesavealpha($tim, true);
					$transparent = imagecolorallocatealpha($tim, 255, 255, 255, 127);
					imagefilledrectangle($tim, 0, 0, 16, 16, $transparent);
					imagecopyresampled($tim, $im, 0, 0, 0, 0, 16, 16, imagesx($im), imagesy($im));
					header('Content-Type: image/png');
					imagepng($tim);
					exit;
				}

			default:
				header('Content-Type: image/png');
				echo base64_decode($game['logo_data']);
				exit;
		}
	}
?>
